﻿// Study0801.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第八章 多态 重载运算符 成员函数 双目运算符

#include <iostream>
using namespace std;

class complex
{
public:
	complex(const double r, const double i) :real_(r), imag_(i) {}
	complex() :complex(0, 0) {}
	complex operator +(const complex& c2) const
	{
		return {this->real_ + c2.real_, this->imag_+c2.imag_};
	}
	complex operator -(const complex& c2) const
	{
		return { this->real_ - c2.real_, this->imag_ - c2.imag_ };
	}
	void display() const
	{
		cout << "(" << real_ << "," << imag_ << ")" << endl;
	}

private:
	double real_, imag_;
};

int main()
{
	const complex c1(5, 4);
	const complex c2(2, 10);
	cout << "c1=";
	c1.display();
	cout << "c2=";
	c2.display();
	 complex c3 = c1 + c2;
	cout << "c3=c1+c2=";
	c3.display();
	c3 = c1 - c2;
	cout << "c3=c1-c2=";
	c3.display();
	return 0;
}

